package com.saturday.swagger;

import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.oas.annotations.EnableOpenApi;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

@Configuration
@EnableOpenApi
@EnableKnife4j
public class SwaggerConfig {

    @Value("${spring.application.name}")
    private String appName;

    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.OAS_30)
                .pathMapping("/")
                .groupName("RestApi")
                .select()
                .apis(SaturdayRequestHandlerSelectors.basePackage("com.saturday.**.controller"))
                .paths(PathSelectors.any())
                .build().apiInfo(new ApiInfoBuilder()
                        .title(appName + "接口文档")
                        .description("前端接口文档")
                        .version("1.0.0")
                        .contact(new Contact("卧龙凤雏"
                                , ""
                                , ""))
                        .build());
    }

    @Bean
    public Docket createFeignApi() {
        return new Docket(DocumentationType.OAS_30)
                .pathMapping("/")
                .groupName("CloudApi")
                .select()
                .apis(SaturdayRequestHandlerSelectors.basePackage("com.saturday.**.provider"))
                .paths(PathSelectors.any())
                .build().apiInfo(new ApiInfoBuilder()
                        .title(appName + "接口文档")
                        .description("微服务接口文档")
                        .version("1.0.0")
                        .contact(new Contact("卧龙凤雏"
                                , ""
                                , ""))
                        .build());
    }

}
